<?php

class userActions extends sfActions {

    public function preExecute() {
        date_default_timezone_set(AppTools::TIMEZONE);
    }

    public function executeIndex(sfWebRequest $request) {
        
    }

    /**
     * Login
     *
     * @param sfWebRequest $request
     */
    public function executeLogin(sfWebRequest $request) {
        $this->form = new FormLogin();
        $referer = $request->getReferer();

        $this->referer = $referer;

        if ($request->isMethod('POST')) {
            $this->form->bind($request->getParameter($this->form->getName()));
            if ($this->form->isValid()) {
                $this->redirect($referer);
            }
        }

        if ($this->getUser()->isAuthenticated()) {
            $this->redirect('@homepage');
        }
    }

    /**
     * Logout
     *
     * @param sfWebRequest $request
     */
    public function executeLogout(sfWebRequest $request) {
        $this->getUser()->signOut();

        $this->redirect('@homepage');
    }

    /**
     * Secure
     *
     * @param sfWebRequest $request
     */
    public function executeSecure(sfWebRequest $request) {
        $this->getUser()->setFlash('warning', 'Таны эрх хүрэлцэхгүй байна!');
        $this->redirect('@homepage');
    }

    /**
     * Error 404
     * 
     */
    public function executeError(sfWebRequest $request) {
        $this->getUser()->setFlash('warning', '<b>' . $request->getUri() . '</b> хаяг олдсонгүй.');
        $this->redirect('@homepage');
    }

}
